package com.neusoft;

import java.util.Calendar;
import java.util.Date;

public class DemoCalendar {

	//获取日历类对象
	public static void main(String[] args) {
		//addCalendar();
		//日历对象转日期对象
		Calendar c = Calendar.getInstance();
		Date time = c.getTime();
		System.out.println(time);
		//日期对象转日历对象
		Date d = new Date();
		c.setTime(d);
	}
	public static void addCalendar(){
		Calendar c = Calendar.getInstance();
		/*c.set(Calendar.YEAR, 2022);
		c.set(Calendar.MONTH, 10);
		c.set(Calendar.DAY_OF_MONTH, 30);
		c.set(2025, 5, 29);*/
		c.add(Calendar.YEAR, 10);
		c.add(Calendar.MONTH, 2);
		c.add(Calendar.DAY_OF_MONTH, -10);
		
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH)+1;
		int day = c.get(Calendar.DATE);
		int hour = c.get(Calendar.HOUR);
		int m = c.get(Calendar.MINUTE);
		int s = c.get(Calendar.SECOND);
		int x = c.get(Calendar.WEEK_OF_MONTH);
		System.out.println(year+"年"+month+"月"+day+"日,"+hour+"时"+m+"分"+s+"秒");
		System.out.println("星期"+x);
	}
	public static void setCalendar(){
		Calendar c = Calendar.getInstance();
		/*c.set(Calendar.YEAR, 2022);
		c.set(Calendar.MONTH, 10);
		c.set(Calendar.DAY_OF_MONTH, 30);
		c.set(2025, 5, 29);*/
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH)+1;
		int day = c.get(Calendar.DATE);
		int hour = c.get(Calendar.HOUR);
		int m = c.get(Calendar.MINUTE);
		int s = c.get(Calendar.SECOND);
		int x = c.get(Calendar.WEEK_OF_MONTH);
		System.out.println(year+"年"+month+"月"+day+"日,"+hour+"时"+m+"分"+s+"秒");
		System.out.println(x);
	}
	public static void showCalendar(){
		Calendar c = Calendar.getInstance();
		System.out.println(c);
		//获取系统时间的年份
		//Calendar.YEAR
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH)+1;
		int day = c.get(Calendar.DATE);
		System.out.println(year+"年"+month+"月"+day+"日");
	}
	
	/*
	 * java.util.GregorianCalendar
	 * [time=1600241649329,areFieldsSet=true,areAllFieldsSet=true
	 * ,lenient=true,zone=sun.util.calendar.ZoneInfo
	 * [id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=
	 * false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,
	 * ERA=1,YEAR=2020,MONTH=8,WEEK_OF_YEAR=38,WEEK_OF_MONTH=3
	 * ,DAY_OF_MONTH=16,DAY_OF_YEAR=260,DAY_OF_WEEK=4,
	 * DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,
	 * MINUTE=34,SECOND=9,MILLISECOND=329,ZONE_OFFSET=28800000,DST_OFFSET=0]

	 */
}
